Page({
  data: {
    dialogVisible: false,
    list: [],
    id: ''
  },

  swipeClose(ev) {
    console.log(ev, 1111);
    this.setData({
      id: ev.mark.id
    })
    const {
      position,
      instance
    } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })


      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  goDetail(e) {
    // data-id   e.currentTarget.dataset.id
    // mark:id   e.mark.id
    console.log(e);
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + e.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },

  // 获取房屋列表
  async onLoad() {
    this.getData()
  },
  // 获取房屋列表
  async getData() {
    const res = await wx.http.get('/room')
    this.setData({
      list: res.data
    })
    console.log('房屋列表', res);
  },
  // 确定框事件
  async dialogClose(e) {
    console.log(e);
    if (e.detail === "confirm") {
      await wx.http({
        url: '/room/' + this.data.id,
        method: 'DELETE'
      })
      wx.showToast({
        title: '删除房屋成功',
      })
      // 刷新列表
      this.getData()
    }
  }
})